package com.zfjt.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.GlobalBean;
import com.zfjt.utils.MD5keyBean;

/**
 * 总接口，所有接口都走这个路径
 * @author xk
 * @version 1.0
 * @date 2017年3月25日
 */
@Controller
public class GlobalController {
	
	@RequestMapping(value="GlobalController",method = RequestMethod.POST)
	@ResponseBody
	public ModelAndView addAnimal(HttpSession hseesion,HttpServletRequest req,HttpServletResponse rep){
		//接收客户端发过来的参数
		String request = req.getParameter("HotelCalifornia");
		System.out.println("=====请求参数====" + request);
		//把参数转换成对象，方便取值
		GlobalBean requestdata = JSON.parseObject(request, GlobalBean.class); 
		//校验码
		String token = requestdata.getToken();
		//接口号
		String pack_on = requestdata.getPack_no();
		//请求时间
		String date = requestdata.getDate();
		//user_id
		String user_id = requestdata.getUser_id();
		//具体参数
		String data = requestdata.getData();
		//验证信息,如果校验码正确跳转接口类传参数过去，错误则带001过去
		if(token.equals(MD5keyBean.newInstance().getkeyBeanofStr("n'u#+lFhgjf**g5656===7hk%A0y@;$65(~9" + user_id + pack_on + date))){
			hseesion.setAttribute("data", data);
		}else{
			hseesion.setAttribute("data",InterfaceDefinition.IStatusCode.TOKEN_FAILURE);
		}
		//跳转到相应接口的控制器
		return new ModelAndView("redirect:/" + pack_on);
		
	}

}
